<?php
class MY_Model extends CI_Model
{   
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function list_tab($table)
    {
        return $this->db->get($table)->result_array();
    }
    
    public function action_tab($table, $data = array(), $col='', $id='')
    {
        if(is_null($data)){
            return false;
        }
        if($id != '')
        {
            $this->db->where($col, $id);
            $this->db->update($table, $data);
        }
        else
        {
            $this->db->insert($table,$data);
        }
        
    }
    public function detele_one($table, $col, $id)
    {
        $this->db->where($col, $id);
        $this->db->delete($table);
    }
    
    public function get_one($table, $col, $id)
    {
        $this->db->from($table);
        $this->db->where($col, $id);
        $query = $this->db->get();
        $data = array();
        if($query->num_rows() > 0)
        {
            $data = $query->result_array();
            
        }
       
        return $data;
        
    }
    
    public function join_tabs($table1, $col1, $table2, $col2)
    {
        $this->db->select('*');
        $this->db->from($table1);
        $this->db->join($table2, "$table2.$col2 = $table1.$col1");
        $query = $this->db->get();
        $data = array();
        if($query->num_rows() > 0)
        {
            $data =  $query->result_array();
        }
        return $data;
    }
    
    
}